home *** CD-ROM | disk | FTP | other *** search
-
- /*
- File: GXGraphics.h
-
- Contains: QuickDraw GX to PostScript conversion code.
- This module contains handy printing library routines.
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1995-1997 by Apple Computer, Inc., all rights reserved.
- */
-
-
- /*************
-
- ******************* QuickDraw Shape Stuff *******************
-
- The QuickDraw Shape type.
- Implemented here as a rectangle shape with a tag.
- The quickDrawPictStruct is the geometry of the QD shape.
- This is a private structure. There is a public API
- for setting and getting the relevant information.
-
- The DrawShape is the tricky part:
- First, if the shape not picture or a QD shape, the real GXDrawShape is just called.
- If it is a picture, my cheezy picture traversal code is used. This code maintains
- the transform hiearchy and viewports of the parent picture. (Actually only transform
- mappings are obeyed, clips are ignored - just lazy I guess. The real gx graphics Traverse
- Picture code will ultimately be used so don't worry.
-
- The QuickDrawShape is drawn in the following manner:
- A picture is created that has the same transform as the QuickDraw shape does.
- The translator is then installed in a port and the QD pict is drawn.
- The translator sends the shape to the callback.
- The callback makes the one shape in the above mentioned picture the shape passed in.
- The picture is then drawn. This has the effect of making the shapes generated by
- the translator obey the transform of the QuickDraw shape. Thus the whole PICT obeys
- the transform. Pretty tricky, huh?
-
- **************/
-
-
-
- /****************** gx graphics integrated implementation *******************************/
-
- #include <Aliases.h>
- #include <String.h>
- #include <GXEnvironment.h>
- #include "IOUtilities.h"
- #include "ShapeUtilities.h"
- #include "Private.h"
-
- /*****************************************
-
- GetShapeType:
-
- Returns the type of a shape.
- Checks for QD shapes.
-
- (If it is a rectangle and has the tag)
-
- *******************************************/
- gxShapeType QGXGetShapeType(gxShape source)
- {
- gxShapeType theType = GXGetShapeType(source);
-
- if ( (theType == gxRectangleType) && (GXGetShapeTags(source, gxQuickDrawPictTag, 1, gxSelectToEnd, nil) > 0) )
- theType = gxQuickDrawPictType;
-
- return(theType);
- }
-
-
-
-
-
-
-
- /************************* Code for translation of a QuickDraw shape ******************************/
-
-
- /*** GrafPort wrapper for doing the translation so bottleneck can get to necessary information ***/
-
- #define kQDBufferSize 1024
-
- typedef struct {
-
- CGrafPort thePort; // The graf port
- short refnum; // file refnum.
- unsigned char buffer[kQDBufferSize]; // input buffer.
- long bufferPosition; // buffer position.
- long bufferSize; // Size of buffer.
- OSErr status; // Place to stick error.
-
- } TQDTranslationGrafPort;
-
-
- OSErr QGXStreamReadBuffer(TQDTranslationGrafPort *translationPort);
- OSErr QGXStreamReadBuffer(TQDTranslationGrafPort *translationPort)
- {
- OSErr status;
- long count;
-
- count = kQDBufferSize;
-
- status = FSRead(translationPort->refnum, &count, &(translationPort->buffer[0]));
- translationPort->bufferSize = count;
- translationPort->bufferPosition = 0;
-
- if (status == eofErr) // end of file is okay.
- status = noErr;
-
- ncheck(status);
- return(status);
-
- }//QGXStreamReadBuffer
-
-
- /************
- BottleNeck for spooling a PICT from disk
- **************/
- pascal void QGXGetPicProc(unsigned char *data, short count);
- pascal void QGXGetPicProc(unsigned char *data, short count)
- {
- OSErr status = noErr;
- long remaining;
- long copy;
- Ptr dataPtr;
- TQDTranslationGrafPort *translationPort;
-
- GetPort((GrafPtr *) &translationPort);
-
- remaining = count;
- dataPtr = (Ptr)data;
- while (remaining > 0) {
-
- if ( (translationPort->bufferSize - translationPort->bufferPosition) >= remaining) {
-
- /** There is enough in the buffer to finish **/
-
- BlockMoveData(&(translationPort->buffer[translationPort->bufferPosition]), dataPtr, remaining);
- translationPort->bufferPosition += remaining;
- remaining = 0;
-
- } else {
-
- /** Copy the remainder of the buffer, read a new buffer **/
-
- copy = translationPort->bufferSize - translationPort->bufferPosition;
- BlockMoveData(&(translationPort->buffer[translationPort->bufferPosition]), dataPtr, copy);
- remaining -= copy;
- dataPtr += copy;
-
- status = QGXStreamReadBuffer(translationPort);
- nrequire(status, failed_read);
-
- }//end if
-
- }//end while
-
- failed_read:
-
- translationPort->status = status;
-
- /** Maybe this will make QuickDraw stop drawing the picture **/
-
- if (status != noErr)
- memset(data, 0xFF, (long)count);
-
-
- }//QGXGetPicProc
-
-
-
- /******************************************
-
- GXTranslateQuickDrawPict:
-
- Routine is called by a client to get individual
- GX shapes from the QD pict. The shapes are handed
- to the client using the callback and the refcon in
- the same manner that installing the translator on a
- grafPort does.
-
- This routine makes it easy for any client to deal
- with QD shapes.
-
- source: The source QD shape.
- userFunction: Function for translator to call back with shapes.
- refCon: You pass it in, we pass it back to your userFunction.
- stats: Statistics generated by the translator.
-
- *********************************************/
- OSErr QGXTranslateQuickDrawPict(gxShape source, gxShapeSpoolUPP userFunction,
- long refCon, gxTranslationStatistic *stats)
- {
- OSErr status, saveStatus;
- GrafPtr curPort;
- TQDTranslationGrafPort *translationPort;
- gxTag geometryTag;
- gxQuickDrawPict *shapeGeometry;
- FSSpec fileSpec;
- AliasHandle hAlias;
- short fileCount = 1;
- short refnum;
- CQDProcs spoolProcs;
- PicHandle pictToDraw;
- Rect destRect;
- gxRectangle theRectangle;
- #if GENERATINGPOWERPC
- RoutineDescriptor getPICTrtnDesc = BUILD_ROUTINE_DESCRIPTOR(uppQDGetPicProcInfo, QGXGetPicProc);
- QDGetPicUPP getPICTUPP = (QDGetPicUPP) &getPICTrtnDesc;
- #else
- QDGetPicUPP getPICTUPP = (QDGetPicUPP) QGXGetPicProc;
- #endif
-
- require_action((QGXGetShapeType(source) == gxQuickDrawPictType), failed_shapeType, status = -9999;);
-
- /** Make a quickdraw version of the rectangle for the destRect **/
-
- GXGetRectangle(source, &theRectangle);
- destRect.top = theRectangle.top >> 16;
- destRect.bottom = theRectangle.bottom >> 16;
- destRect.left = theRectangle.left >> 16;
- destRect.right = theRectangle.right >> 16;
-
- /******* Get the QuickDraw pict information from the shape ********/
-
- GXGetShapeTags(source, gxQuickDrawPictTag, 1, 1, &geometryTag);
- GXLockTag(geometryTag);
- shapeGeometry = (gxQuickDrawPict*)GXGetTagStructure(geometryTag, nil);
-
- nrequire(status = GXGetGraphicsError(nil), failed_getAndLockTag);
-
- /* Make an alias handle from the data in the tag */
-
- status = PrNewHandle((Handle*)&hAlias, shapeGeometry->alias.aliasRecordSize);
- nrequire(status, failed_newHandle);
-
- BlockMoveData((Ptr)&(shapeGeometry->alias.aliasRecord[0]), *hAlias, shapeGeometry->alias.aliasRecordSize);
-
- /* Get the file spec from the alias handle */
- {
- Boolean needsUpdate = false;
- status = MatchAlias( nil, kARMSearch + kARMNoUI + kARMMountVol,
- hAlias, &fileCount, &fileSpec, &needsUpdate, nil, nil);
- }
- nrequire(status, failed_Match);
-
- /* Now open the file */
-
- status = FSpOpenDF(&fileSpec, fsRdPerm, &refnum);
- nrequire(status, failed_open);
-
- /* Set the file position */
-
- #if DEBUGLEVEL >= DEBUGFEEDBACK
- dprintf(trace, "file position: %d", (unsigned char *) shapeGeometry->alias.fileOffset);
- dprintf(trace, "qd shape stream size: %d", (unsigned char *) shapeGeometry->dataLength);
- #endif
-
- status = SetFPos(refnum, fsFromStart, shapeGeometry->alias.fileOffset);
- nrequire(status, failed_setPos);
-
- /****** Set up a port for the translator with our buffer in it ******/
-
- status = PrNewPtr((Ptr *) &translationPort, sizeof(TQDTranslationGrafPort));
- nrequire(status, failed_NewPtr);
-
- translationPort->bufferPosition = 0;
- translationPort->bufferSize = 0;
- translationPort->refnum = refnum;
- GetPort(&curPort);
- OpenCPort((CGrafPtr)translationPort);
- SetPort((GrafPtr)translationPort);
- SetStdCProcs(&spoolProcs);
- spoolProcs.getPicProc = getPICTUPP;
- translationPort->thePort.grafProcs = &spoolProcs;
-
- /* Draw the data through the translator */
-
- status = PrNewHandle(&(Handle)pictToDraw, sizeof(Picture));
- nrequire(status, failed_newPicHandle);
- (*pictToDraw)->picFrame = shapeGeometry->srcRect;
-
- GXInstallQDTranslator((GrafPtr)translationPort, shapeGeometry->options,
- &shapeGeometry->srcRect,
- &destRect,
- shapeGeometry->styleStretch,
- userFunction,
- (void*)refCon);
-
- DrawPicture(pictToDraw, &shapeGeometry->srcRect);
-
- *stats = GXRemoveQDTranslator((GrafPtr)translationPort, nil);
-
- DisposeHandle((Handle)pictToDraw);
-
- failed_newPicHandle:
-
- SetPort(curPort);
-
- CloseCPort((CGrafPtr)translationPort); // Josh said not doing this can cause crash under display mgr.
- DisposePtr((Ptr)translationPort);
-
- failed_NewPtr:
- failed_setPos:
-
- saveStatus = FSClose(refnum);
- ncheck(saveStatus);
- if (status == noErr)
- status = saveStatus;
-
- failed_open:
- failed_Match:
-
- DisposeHandle((Handle)hAlias);
-
- failed_newHandle:
-
- GXUnlockTag(geometryTag);
-
- failed_getAndLockTag:
- failed_shapeType:
-
- return(status);
-
- }//QGXTranslateQuickDrawPict
-